<?php 
/*
 * NetfilterEyes - 2008 - Anouar Belkacem
 * This code is a modified copy of the FirewallEyes project source code
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or (at
 * your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 */

session_start(); 
include("./configuration.php"); 
include("./include.php");

// authentification check
authenticationCheck();

// Date in the past
header("Expires: Mon, 26 Jul 2004 00:00:00 GMT");

// always modified
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
 
// HTTP/1.1
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);

// HTTP/1.0
header("Pragma: no-cache");

set_time_limit (300);

$logfile = $_GET["logfile2display"] ;
$_SESSION['logfile2display'] = ($logfile ? $logfile :  $_SESSION['logfile2display']);

$displayedLines=($_GET["displayedLines"] ? $_GET["displayedLines"] : $configuration["displayedLines"]);
$_SESSION['displayedLines'] = $displayedLines ;

// get inputs
$criteria=$_GET["criteria"];
$_SESSION['criteria'] = $criteria; 

$configurationVars=Array("resolvService","exactSearch");
foreach($configurationVars as $confVarName) {
  if ( $_GET["searchAction"] == 1 ) {
    $_SESSION[$confVarName] = $_GET[$confVarName] ;
  }
}

// init
$lineCount=0;
$indexForAction=getIndexForColumn("action",$logFields);
$indexForProtocol=getIndexForColumn("protocol",$logFields);

$maxWidth=0;
for($i=0; $i<count($logFields); $i++) {
	$maxWidth+=$logFields[$i][2];
}

?> 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
	<title>NetfilterEyes - An Ajax Netfilter's log viewer</title>
	<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
	<link href="log.css" rel="stylesheet" type="text/css"/>
	<script type="text/javascript" src="js/ajax.js"> </script>
	<script type="text/javascript" src="js/logtail.js"> </script>
	<script>
  	function myrefresh() {
  		<?php if ($automaticSubmit) {?>
  		document.forms["searchForm"].submit() ;
  		<?php } ?>
  	}
  	function filter() {
  		<?php if ($automaticSubmit) {?>
  		document.forms["filterForm"].submit() ;
  		<?php } ?>
  	}
	</script>
</head>

<body>
<?php

require_once("header.php");
if ( $_GET["searchAction"] == 1 || $_GET["filterAction"] =="1" ) { ?>
  <script>
    getLog('start') ;
  </script>
<?php 
}

if ( isset( $_GET["info"] ) ) include("info.php") ;
else {
?>

<div id="buttons">
  <a href="#" onclick="getLog('start');">
    <img src="./images/media_play.gif" alt="Start Viewer" title="Start Viewer"/>
  </a>
  <a href="#" onclick="stopTail();">
    <img src="./images/media_pause.gif" alt="Pause Viewer" title="Pause Viewer"/>
  </a>
</div>

    
<table style="padding-left:18px;" border="0" cellpadding="0" cellspacing="0" width="<?=$maxWidth?>">
	<tr>
    <?php 
    // tab header
    for($i=0; $i<count($logFields); $i++) { 
    	?>
      <td class="header"><span style="width: <?=$logFields[$i][2]?>px">&nbsp;<?=$logFields[$i][0]?></span></td>
      <?php 
    } ?>
	</tr>
	<tr>
	  <form method="GET" action="index.php" style="margin: 0px;padding: 0px;" name="filterForm">
      <input type="hidden" name="filterAction" value="1"/>
		<?php
    // search form 
		for($i=0; $i<count($logFields); $i++) { 
			?><td>
          <span style="width: <?=$logFields[$i][2]?>px">
          <input type="text" name="criteria[<?=htmlentities($logFields[$i][0])?>]" 
          value="<?=htmlentities(stripslashes($criteria[$logFields[$i][0]]))?>" 
          style="width: <?=$logFields[$i][2]?>px" class="inputText" 
          onChange="filter()">
          </span>
			</td>
		<?php 
		} ?>
		<!--input class="button" type="submit" value="GO"--> 
	 </form>
	</tr>
</table>

<div id="log"></div>
<? 
// end of else
} ?>

<div id="footer">
      NetfilterEyes - <A HREF="http://www.gnu.org/licenses/gpl.html" target="new"> GPL </A>
</div>
</body>
</html>
